<template>
	<view class="head-count">
		<view class="head-count-item" @click="jump('/pages_merchant/merchant_list/merchantList')">
			<view class="member-count">
				{{countList.merchant_num}}
			</view>
			<view class="member-label">
				商家商户总数(个）
			</view>
			<view class="add-count-module">
				<view class="add-item day">
					<text class="text">今日+{{countList.merchant_today}}</text>
				</view>
				<view class="add-item week">
					<text class="text">今周+{{countList.merchant_week}}</text>
				</view>
				<view class="add-item month">
					<text class="text">今月+{{countList.merchant_month}}</text>
				</view>
			</view>
		</view>
		<view class="head-count-item" @click="jumpTeam">
			<view class=" member-count">
				{{countList.team_num}}
			</view>
			<view class="member-label">
				团队管理(人）
			</view>
			<view class="add-count-module">
				<view class="add-item day">
					<text class="text">今日+{{countList.team_today}}</text>
				</view>
				<view class="add-item week">
					<text class="text">今周+{{countList.team_week}}</text>
				</view>
				<view class="add-item month">
					<text class="text">今月+{{countList.team_month}}</text>
				</view>
			</view>
		</view>
	</view>
</template>

<script lang="ts" setup>
	import { onMounted, ref, Ref } from 'vue';
	import REST_URL from '@/http/http.restUrl';
	import { ICountList } from './types';
	import { useStore } from 'vuex';
	import { USER_LEVEL_TYPE } from '@/enum/level';
	import { GET_STORE_USERINFO } from '@/store/gettersType';
	
	
	const store = useStore();

	const countList : Ref<ICountList> = ref({
		team_num: 0, //团队人数
		merchant_num: 0, //商户人数
		team_today: 0,//今日新增团队人数
		team_week: 0, //今周新增团队人数
		team_month: 0, //今月新增团队人数
		merchant_today: 0, //今日新增商户人数
		merchant_week: 0, //今周新增商户人数
		merchant_month: 0, //今月新增商户人数
	})

	onMounted(async () => {
		await uni.loginManger.$interceptor;
		getHeadCount();
	})

	const getHeadCount = async () : Promise<void> => {
		const result : ICountList = (await uni.http.POST(REST_URL.homeHeadCount, {
			customer_id: store.getters[GET_STORE_USERINFO].id,
		})).data
		countList.value = result;
	}

	const jump = (path : string) => {
		uni.router.route(path);
	}

	const jumpTeam = () => {
		if (store.state.userInfo && store.state.userInfo.customer_type < USER_LEVEL_TYPE.DIRECTOR) {
			uni.prompt.$showToast('当前账号无权限')
			return
		};
		uni.router.route('/pages_team/member_list/memberList');
	}
</script>

<style scoped lang="scss">
	@import "./headCount.scss";
</style>